﻿using HomagChina.Basic.CCT.Db.CCT_Db;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Proxy
{
    public class DeleteInfoHandle
    {
        public DeleteInfoHandle()
        {
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool DeletedSettingInfo(int Id, string Type)
        {
            bool result = false;
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    if (Type == "Appliances")
                    {
                        var Info = Db.T_MachineInfo.FirstOrDefault(s => s.Id == Id);
                        Db.T_MachineInfo.Remove(Info);
                        result = Db.SaveChanges() > 0;
                    }
                    else if (Type == "DirectionConfig")
                    {
                        var aa = Db.T_DirectionConfig.Where(s => s.Id == Id).FirstOrDefault();
                        Db.T_DirectionConfig.Remove(aa);
                        result = Db.SaveChanges() > 0;
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                return result;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="Upi"></param>
        /// <returns></returns>
        public bool DeleteBoardInfoByUpi(int Id)
        {
            bool result = false;
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    var BoardInfo = Db.T_TransOnlineRecords.Where(s => s.Id == Id).FirstOrDefault();
                    Db.T_TransOnlineRecords.Remove(BoardInfo);
                    result = Db.SaveChanges() > 0;
                }
                return result;
            }
            catch (Exception ex)
            {
                return result;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="Upi"></param>
        /// <returns></returns>
        public bool DeleteBoardInfoByUpi(string Upi)
        {
            bool result = false;
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    var BoardInfo = Db.T_TransOnlineRecords.Where(s => s.Reference == Upi).FirstOrDefault();
                    Db.T_TransOnlineRecords.Remove(BoardInfo);
                    result = Db.SaveChanges() > 0;
                }
                return result;
            }
            catch (Exception ex)
            {
                return result;
            }
        }


        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool DeleteOnLineRecords(string Location = "")
        {
            bool result = false;
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    var OnlineRecordsInfo = Location == ""
                                                    ? Db.T_TransOnlineRecords.ToList()
                                                    : Db.T_TransOnlineRecords.Where(s => s.Location == Location).ToList();
                    Db.T_TransOnlineRecords.RemoveRange(OnlineRecordsInfo);
                    result = Db.SaveChanges() > 0;
                }
                return result;
            }
            catch (Exception ex)
            {
                return result;
            }
        }
    }
}